﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.Core;
using PNProject.Core.Converter;

namespace PNProject
{
    public class PublicService
    {
        public static List<SupportModel> GetAllSupport()
        {
            var list = StaticData.supportRepo.GetAll();
            List<SupportModel> data = new List<SupportModel>();
            foreach (var item in list)
            {
                SupportModel sup = new SupportModel()
                {
                    ID = item.SupportID.ToString(),
                    Name = item.Name,
                    Description = item.Description,
                    Nick = item.Nick,
                    Type = item.Type.HasValue ? item.Type.Value.ToString() : "no"
                };
                data.Add(sup);
            }
            return data;
        }

        public static List<ItemModel> GetAllItems(int type)
        {
            var list = StaticData.itemRep.GetAll();
            List<ItemModel> data = new List<ItemModel>();
            foreach (var item in list)
            {
                var defaultImage = item.ImagesItems.OrderByDescending(a => a.OrderNumber).FirstOrDefault();
                var defaultDetail = item.ItemDetails.SingleOrDefault();
                var sup = ItemConverter.ItemTo(item);
                //ItemModel sup = new ItemModel()
                //{
                //    ItemId = item.ItemID,
                //    Url =  defaultImage!=null ?defaultImage.Url:string.Empty,
                //    Description = defaultDetail!=null?defaultDetail.Description:string.Empty
                    
                //};
                data.Add(sup);
            }
            return data.OrderByDescending(a=>a.ItemId).ToList();
        }
    }
}